--[[	-- comment out, as not entirely functional yet, and seems to be somehow overriding the cob...
-- Lvl 1 regular forces heavy vehicle/ tank
local base, body, turret, barrel, flare, track3, track2, track1 = piece ("base", "body", "turret", "barrel", "flare", "track3", "track2", "track1")		

-- constants (ie static-vars):
local bmoving = 0
local restore_delay = Spring.UnitScript.GetLongestReloadTime(unitID) * 2
local treadnum = 3

-- Signal definitions
local SIG_AIM = 2
--local SIG_MOVE = 4 	-- not yet in use

-- includes
include "rockunit.lua"
include "smokeunit.lua"	-- see comments at smokescript below.

function script.Create(unitID)
	Hide(track2)
	Hide(track1)
	Hide(flare)
--	treadnum = 3; set elsewhere
--	bmoving = 0;
	smokePieces = { body } -- which pieces are to emit smoke.. so why was this used to be needed, and why not included in "script_stumpy.lua" ? Maybe it was assuming different smokeunit.lua...
	StartThread(SmokeUnit(smokePieces))	-- the get's the argument to where it's supposed to go 
end										-- (at least the table length is read correctly), however no smoking... maybe change value back to what it was ?
										-- works! it was the wrong number I was using (why the change ? dunno. Starts from 1 rather than -1 ? :P )
--Smokescript is in external file that any/all units can use - see the "includes"

-- ok, no movement animation to start with
-- gotracks()
-- {
-- while( TRUE ) 
   -- { 
        -- if(bMoving) 
           -- { 
              -- if(treadnum == 3) 
              -- {    
              -- show track3;         
              -- hide track2; 
              -- hide track1; 
              -- } 
            -- if(treadnum == 2) 
            -- { 
              -- show track2;         
              -- hide track3; 
              -- hide track1;
			-- }
            -- if(treadnum == 1) 
            -- { 
              -- show track1;         
              -- hide track2; 
              -- hide track3;
			-- }
            -- treadnum = treadnum - 1;
            -- if (treadnum == 0)
            	-- { 
            	-- treadnum = 3;
            	-- }
         -- } 
      -- sleep 90; 
   -- } 
-- }

-- StartMoving()
-- {

	-- signal SIG_MOVE;
	-- set-signal-mask SIG_MOVE;
	-- bmoving = 1;
	-- start-script gotracks();
-- }

-- StopMoving()
-- {
	-- signal SIG_MOVE;
	-- bmoving = 0;
-- }


-- this was included into the variable's initialisation I think
-- SetMaxReloadTime(Func_Var_1)
-- {
	-- restore_delay = Func_Var_1 * 2;
-- }


local function RestoreAfterDelay(unitID)
	Sleep(restore_delay)
	Turn(turret, y_axis, 0, math.rad(90))	-- at what speed ? old speed was 100.071429 for both, perhaps last value is speed ?
	Turn(turret, x_axis, 0, math.rad(90))        --- 100 should be speed ignore long decimals its a TA curse
end

function script.AimWeapon(weaponID, heading, pitch)
	Signal(SIG_AIM)
	SetSignalMask(SIG_AIM)
	Turn(turret, y_axis, heading, math.rad(90))
	Turn(turret, x_axis, 0 - pitch, math.rad(90))
	WaitForTurn(turret, y_axis)
	WaitForTurn(turret, x_axis)
	StartThread(RestoreAfterDelay)
	return true
end

function script.FireWeapon(weaponID)
	Show(flare)	-- need to use sfx rather than showing and hiding "flare" . Have a look at smokeunit again, that should clarify
	--. in bos: emit-sfx 1024 from flare;   //emit sfx
	Move(turret, z_axis, -2, math.rad(4000))	-- recoil effect - might need to play with the speeds
	Sleep(150)
	Hide(flare)  --- get rid of this too when you figure out emit-sfx
	Move(turret, z_axis, 0, math.rad(1000))
end

function script.AimFromWeapon() 
	return turret 
end

function script.QueryWeapon() 
	return flare 
end

-- nor needed anymore, from what I can discern
-- SweetSpot(piecenum)
-- {
	-- piecenum = base;
-- }

-- for now use simple version:
function script.Killed(recentDamage, maxHealth)
	Hide(flare)    --- you going to need to find out death severity or else everything will blow up dramatically even if barely dying, also that plays into death animations
	Explode(base, SFX.FALL)
	return 1   
end

-- implement later:
-- Killed(severity, corpsetype)
-- {
-- show track3;
-- hide track2;
-- hide track1;

	-- if( severity <= 99 )
	-- {
		-- corpsetype = 1;
		-- explode barrel type BITMAPONLY | BITMAP1;
		-- explode body type BITMAPONLY | BITMAP2;
		-- explode track3 type BITMAPONLY | BITMAP3;
		-- explode turret type BITMAPONLY | BITMAP5;
		-- return (0);
	-- }
	-- corpsetype = 3;
		-- explode barrel type FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP1;
		-- explode body type BITMAPONLY | BITMAP2;
		-- explode track3 type FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP3;
		-- explode turret type FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP5;
		-- return (0);
-- }
--]]